import {
  Body,
  Controller,
  Get,
  Param,
  Post,
  NotFoundException,
} from '@nestjs/common';
import { MessagesService } from './messages.service';
import { CreateMessageDto } from './dto/messages.dto';

@Controller('api/messages')
export class MessagesController {
  constructor(private readonly messagesService: MessagesService) {}

  @Get()
  listMessages() {
    return this.messagesService.getAll();
  }

  @Post()
  createMessage(@Body() body: CreateMessageDto) {
    console.log(body);
    return body;
  }

  @Get(':id')
  getMessage(@Param() { id }) {
    const message = this.messagesService.findOne(id);

    if (!message) {
      throw new NotFoundException('Эй ты хуйню ищещ, да. введи другой id');
    }

    return message;
  }
}
